package com.xhwl.logistics.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.logistics.bo.VehiclePassageBO;
import com.xhwl.logistics.bo.VehiclePassageSecondBO;
import com.xhwl.logistics.bo.cent.DeviceBO;
import com.xhwl.logistics.bo.input.PageBO;
import com.xhwl.logistics.bo.input.QueryVehiclePassageBO;
import com.xhwl.logistics.converter.ToPageBO;
import com.xhwl.logistics.converter.ToPageVO;
import com.xhwl.logistics.converter.mapstruct.VehiclePassageConverter;
import com.xhwl.logistics.dto.manipulate.VehicleSyncDTO;
import com.xhwl.logistics.dto.query.VehiclePassageDTO;
import com.xhwl.logistics.entity.VehiclePassage;
import com.xhwl.logistics.service.IVehiclePassageService;
import com.xhwl.logistics.service.business.VehiclePassageBusinessService;
import com.xhwl.logistics.service.cent.QueryDeviceSecondService;
import com.xhwl.logistics.vo.PageVO;
import com.xhwl.logistics.vo.VehiclePassageSecondVO;
import com.xhwl.logistics.vo.VehiclePassageThirdVO;
import com.xhwl.logistics.vo.VehiclePassageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

//@RestController
public class VehiclePassageController {

    @Autowired
    private VehiclePassageConverter vehiclePassageConverter;

    @Autowired
    private ToPageBO toPageBO;

    @Autowired
    private ToPageVO toPageVO;

    @Autowired
    private IVehiclePassageService vehiclePassageService;

    @Autowired
    private VehiclePassageBusinessService vehiclePassageBusinessService;

    @Autowired
    private QueryDeviceSecondService queryDeviceSecondService;

    @PostMapping("/passage/page")
    ResultJson<PageVO<VehiclePassageVO>> passage(@RequestBody VehiclePassageDTO vehiclePassageDTO) {

        QueryVehiclePassageBO queryVehiclePassageBO = vehiclePassageConverter.vehiclePassageDTO2QueryVehiclePassageBO(vehiclePassageDTO);
        PageBO pageBO = toPageBO.toPageBOForPassage(vehiclePassageDTO);

        IPage<VehiclePassageBO> vehiclePassageBOIPage = vehiclePassageService.queryPassage(queryVehiclePassageBO, pageBO);

        PageVO<VehiclePassageVO> pageVO = toPageVO.toPageVO(vehiclePassageBOIPage, vehiclePassageConverter.vehiclePassageBOList2VehiclePassageVOList(vehiclePassageBOIPage.getRecords()));
        return ResultJson.successWithResult(pageVO);
    }

    @GetMapping("/passage/list")
    ResultJson<List<VehiclePassageSecondVO>> passage(Integer projectId) {
        List<VehiclePassageSecondBO> vehiclePassageSecondBOList = vehiclePassageBusinessService.queryPassage(projectId);

        return ResultJson.successWithResult(vehiclePassageConverter.vehiclePassageSecondBOList2VehiclePassageSecondVOList(vehiclePassageSecondBOList));
    }

    /**
     * 车流统计的车场实时监控中获取通道信息
     */
    @PostMapping("/passage/message")
    public ResultJson<List<VehiclePassageThirdVO>> getPassageMessage(@RequestBody VehicleSyncDTO vehicleSyncDTO){
        List<VehiclePassage> vehiclePassageList = vehiclePassageService.queryPassageMessage(vehicleSyncDTO.getProjectId());

        List<DeviceBO> deviceBOS = queryDeviceSecondService.queryDevicesByProjectId(vehicleSyncDTO.getProjectId());
        return ResultJson.successWithResult(vehiclePassageConverter.vehiclePassageList2VehiclePassageThirdVOList(vehiclePassageList,deviceBOS,vehicleSyncDTO.getProjectId()));
    }
}
